package cn.flyboy.mapper;

import cn.flyboy.entity.*;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

// 通过注解编写sql语句
public interface ExamMapper {

    @Select("select e_teacher from exam where e_name=#{param1} and e_isend=0 and e_isstart=1")
    String selectStartExamTeaName(String e_name);

    @Select("select * from exam")
    List<Exam> selAllExam();

    @Select("select e.e_name,e.e_starttime,e.e_teacher,e.e_isend, e.e_clear, e.e_isstart,e.e_examination from exam e, student s where e.e_name = s.stu_exam and s.stu_id=#{param1}")
    List<the_exam> selAllExamFromStu(String stuId);

    @Select("select * from exam where e_isend=0 and e_isstart=1")
    List<Exam> selStartExam();

    @Select("select * from exam where e_teacher=#{param1}")
    List<Exam> getAllTeaExam(String teaID);

    @Select("select * from answer where exam_name=#{param1} and tea_name=#{param2}")
    List<Answer> selFileAnswerName(String examName, String teaName);

    @Select("select s.stu_id,s.stu_name,s.stu_class,a.exam_name,a.file_name,a.times from student s,answer a where a.exam_name=#{param1} and a.tea_name=#{param2} and a.stu_id=s.stu_id")
    List<the_answer> selStuAnswer(String examName, String teaName);


    @Select("select e_examination from exam where e_name=#{param1} and e_teacher=#{param2}")
    String selFileByName(String e_name, String e_teacher);

    @Update("update exam set e_name=#{param2.e_name},e_starttime=#{param2.e_starttime},e_autostart=#{param2.e_autostart} where e_name=#{param1}")
    int updExam(String e_oldname, Exam exam);

    @Update("update exam set e_isend=1 where e_name=#{param1}")
    int updStopExam(String e_name);

    @Update("update exam set e_clear=1 where e_name=#{e_name}")
    int updClearExam(String e_name);

    @Update("update exam set e_examination=#{param2} where e_name=#{param1}")
    int savePager(String e_name, String originalFileName);

    @Update("update exam set e_isstart=1 where e_name=#{param1}")
    int updIsStart(String e_name);

    @Delete("delete from answer where exam_name=#{param1} and tea_name=#{param2}")
    int delAnswer(String examName, String teaName);

    @Delete("delete from exam where e_name=#{param1} and e_teacher=#{param2}")
    int delExam(String examName, String teaName);


    @Update("update answer set file_nam=#{param1.file_name},file_size=#{param1.file_size} where stu_id=#{param1.stu_id} and exam_name=#{param1.exam_name}")
    int upAnswer(Answer answer);

    @Insert("insert into answer(stu_id,exam_name,tea_name,file_name,file_size,times) value(#{stu_id},#{exam_name},#{tea_name},#{file_name},#{file_size},#{times})")
    int saveAnswer(Answer answer);

    @Insert("insert into exam value(#{e_name},#{e_starttime},#{e_teacher},#{e_autostart},#{e_isend},#{e_file},#{e_clear},#{e_isstart},#{e_examination})")
    int insExam(Exam exam);
}
